package ink.yql.service.Impl;

import ink.yql.dao.PointDao;
import ink.yql.model.Point;
import ink.yql.model.User;
import ink.yql.service.PointService;
import ink.yql.util.RestObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
@Transactional
public class PointServiceImpl implements PointService {
    @Autowired
    private PointDao pointDao;

    @Autowired
    private HttpServletRequest req;

    @Override
    public RestObject getByUid() {
        User user = (User) req.getSession().getAttribute("user");
        if (user == null) {
            return RestObject.builder().code("404").message("请先登录").build();
        }
        List<Point> list = pointDao.getByUidPraise(user.getUid());
        return RestObject.builder().code("200").message("查询所有点赞成功").data(list).build();
    }

    @Override
    public RestObject getByUidPraise() {
        User user = (User) req.getSession().getAttribute("user");
        if (user == null) {
            return RestObject.builder().code("404").message("请先登录").build();
        }
        List<Point> list = pointDao.getByUidPraise(user.getUid());
        return RestObject.builder().code("200").message("查询所有点赞成功").data(list).build();
    }

    @Override
    public RestObject getByUidHiss() {
        User user = (User) req.getSession().getAttribute("user");
        if (user == null) {
            return RestObject.builder().code("404").message("请先登录").build();
        }
        List<Point> list = pointDao.getByUidHiss(user.getUid());
        return RestObject.builder().code("200").message("查询所有点嘘成功").data(list).build();
    }
}
